home *** CD-ROM | disk | FTP | other *** search
- /*
- COMPHDR.C
-
- Ce programme est un serveur pour TPK. Il remplace les lignes R: du debut
- du message par la liste des BBS empruntees par le message. Le format est
- identique a celui des BBS: "Path: !F6XYZ!etc...."
-
- */
-
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
-
- int ReadDest (char *cmd);
- int ReadFromBbs (char *cmd);
-
- char str[256];
- char line[256];
- char LastHdr[81];
- char Path_Tpk[129];
- char FiMsg[129];
- char FiMsgBak[129];
- char N_Mycall[7]="\0";
- char N_To[7]="\0";
- char N_From[7]="\0";
- char N_Bbs[7]="\0";
- char Typ[2],To[7],From[7],Abbs[41],Bid[13],BidOrg[13];
- char Fbbs[41],FbbsCall[7];
- char Subject[81];
-
- void main(int argc, char *argv[])
- {
- FILE *fichin,*fichout;
- char *s;
- char *ptr;
- char *ptr_path;
- char str_path[1000];
- int WaitFrom,Nbcar;
-
- /* Le premier parametre est le nom du fichier contenant le message */
-
- strncpy(FiMsg, argv[1], 128);
- strcpy(FiMsgBak, FiMsg);
- strcat(FiMsgBak, ".BAK");
-
- /* Le deuxieme parametre est le repertoire de TPK */
-
- strncpy(Path_Tpk, argv[2], 128);
-
- /* Le troisieme parametre est l'indicatif utilise */
-
- strncpy(N_Mycall, argv[3], 6);
-
- if ((rename(FiMsg, FiMsgBak)) == 0)
- {
- if ((fichin=fopen(FiMsgBak, "r")) != NULL)
- {
- if ((fichout=fopen(FiMsg, "w")) != NULL)
- {
- if (fgets(line, 255, fichin) != NULL)
- {
- ReadDest (line);
- fputs(line, fichout);
- if (fgets(Subject, 80, fichin) != NULL)
- {
- fputs(Subject, fichout);
- WaitFrom=1;
- sprintf(str_path, "Path: ");
- Nbcar=6;
- ptr_path=str_path+6;
- while (fgets(line, 255, fichin) != NULL)
- {
- if (WaitFrom)
- {
- if ((s=strstr(line, "R:")) != NULL)
- {
- strcpy(LastHdr, line);
- if (ReadFromBbs (s))
- {
- ptr=str;
- *ptr++='!';
- for (s=Fbbs; *s != '.'; s++ ) *ptr++=*s;
- *ptr='\0';
- Nbcar+=strlen(str);
- sprintf(ptr_path, str);
- ptr_path+=strlen(str);
- if (Nbcar>72)
- {
- sprintf(ptr_path, "\n ");
- ptr_path+=7;
- Nbcar=7;
- }
- }
- }
- else
- {
- WaitFrom--;
- fputs(LastHdr, fichout);
- fputs(str_path,fichout);
- if (Nbcar) fputs("\n", fichout);
- }
- }
- else
- fputs(line, fichout);
- }
- }
- }
- fclose(fichout);
- }
- fclose(fichin);
- }
- remove(FiMsgBak);
- }
- }
-
- /* Lecture des informations dans une ligne de commande SP ou SB */
-
- int ReadDest (char *cmd)
- {
- char *s;
- char *ptr;
- int i;
-
- if (strlen(cmd)>2)
- {
- if (toupper(*cmd)==83)
- {
- s=cmd;
- s=strupr(s);
- *Typ=*++s;
- ptr=To; /* TO */
- i=6;
- for (++s;*s ;s++)
- {
- if (*s==64){ /* @BBS*/
- ptr=Abbs;
- *ptr=0;
- i=40;}
- else if (*s==60){ /* <FROM */
- ptr=From;
- *ptr=0;
- i=6;}
- else if (*s==36){ /* $BID */
- ptr=Bid;
- *ptr=0;
- i=12;}
- else if (*s<33)
- continue;
- else if (i)
- {
- if (*s>32)
- {
- *ptr++=*s;
- *ptr=0;
- i--;
- }
- }
- }
- return strlen(To);
- }
- }
- }
-
- /* Recherche de la BBS d'origine du message dans une ligne R: */
-
- int ReadFromBbs (char *cmd)
- {
- char *s;
- char *ptr;
- int i=0;
- for (s=cmd; *s; s++)
- {
- if (*s==64){
- ptr=Fbbs;
- *ptr=0;
- i=40;
- }
- else if (*s==36){
- ptr=BidOrg;
- *ptr=0;
- i=12;
- }
- else if (*s==58)
- continue;
- else if (*s==32)
- i=0;
- else if (i)
- {
- if (*s>32)
- {
- *ptr++=*s;
- *ptr=0;
- i--;
- }
- }
- }
- return strlen(Fbbs);
- }
-
-